package com.zl.basis.sys;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.zl.basis.component.AppUtil;
import com.zl.basis.config.BasisConstant;
import com.zl.basis.util.StringUtil;

public class DeviceCmdReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (null == intent || StringUtil.isEmpty(intent.getAction())) {
            return;
        }
        if (intent.getAction().equals(BasisConstant.BROADCAST_ACTION_INSTALL_APP)) {
            String apkPath = intent.getStringExtra("apk_path");
            boolean cmd = DeviceUtil.install(apkPath);
            if (!cmd) {
                AppUtil.installApp(context, apkPath);
            }
        } else if (intent.getAction().equals(BasisConstant.BROADCAST_ACTION_DEVICE_REBOOT)) {
            boolean cmd = DeviceUtil.reboot();
            if (!cmd) {
                DeviceUtil.reboot(context);
            }
        }
    }
}
